#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import re
import pytest
import allure
from utils.logger import log
from page_object.searchpage import SearchPage


@pytest.fixture(scope="class", autouse=True)
def init_search(drivers):
    """实例化页面对象"""
    global search
    search = SearchPage(drivers)


@allure.feature("测试百度模块")
class TestSearch:
    @allure.story("测试selenium搜索结果")
    def test_001(self):
        """测试搜索"""
        search.input_search("selenium")
        search.click_search()
        # 断言
        result = re.search(r'selenium', search.get_source)
        log.info(result)

    @allure.story("测试搜索候选")
    @pytest.mark.parametrize("word", ["selenium", "app", "pytest"])
    def test_002(self, word):
        """测试搜索候选"""
        # 输入搜索词
        search.input_search(word)
        log.info(search.imagine)
        # 检查联想词每个都含有搜索词
        assert all([word in i for i in search.imagine])


if __name__ == '__main__':
    # 下面的代码使用pycharm运行可能会没有生成报告，建议使用vscode执行
    import os

    pytest.main(['TestCase/tests_search.py','--alluredir', './allure'])
    os.system('allure serve allure')
